From 26974db1aa90b565de2c1860c25d61adb00ad5a1 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Fri, 2 Aug 2013 04:03:11 +0200 Subject: [PATCH] legacy upload.js: Clean up and remove from jshintignore * Coding style: - Braces - Single quotes - Dot instead of bracket access for properties * Fixed various implied global/static variables, most significantly the for-loop variable 'cached' etc. * Changed == '' to ! since === '' will require it to be a string and == '' returns true for almost anything that is falsy, no good way to choose a strict alternative. * Changed setAttribute('disabled', ..) to using .property instead. * Using setTimeout as a global instead of as a window property. * Using other globals from wikibits.js through window property, as they are defined. * Use a closure instead of string eval() in setTimeout(). * Made local equivalents for some global variables for access inside the closure. * Don't create functions in a loop. Moved the onchange function outside the loop and re-used it for each one (safe in this case, and more efficient). * Call setTimeout/clearTimeout as global, no need for the window object as host. Change-Id: I9df912ee48d30c189394bf07f5e49014220f36a3 --- .jshintignore | 1 - skins/common/upload.js | 267 +++++++++++++++++++++++------------------ 2 files changed, 153 insertions(+), 115 deletions(-) diff --git a/.jshintignore b/.jshintignore index 5fbbf8166d..bc10ad83b6 100644 --- a/.jshintignore +++ b/.jshintignore @@ -28,7 +28,6 @@ resources/jquery.chosen/chosen.jquery.js # legacy scripts skins/common/IEFixes.js skins/common/config.js -skins/common/upload.js # github.com/jshint/jshint/issues/729 tests/qunit/suites/resources/mediawiki/mediawiki.jscompat.test.js diff --git a/skins/common/upload.js b/skins/common/upload.js index 160de86161..580cf255ad 100644 --- a/skins/common/upload.js +++ b/skins/common/upload.js @@ -1,12 +1,14 @@ +/*jshint camelcase:false */ ( function ( mw, $ ) { -var ajaxUploadDestCheck = mw.config.get( 'wgAjaxUploadDestCheck' ), +var licenseSelectorCheck, wgUploadWarningObj, wgUploadLicenseObj, fillDestFilename, + ajaxUploadDestCheck = mw.config.get( 'wgAjaxUploadDestCheck' ), fileExtensions = mw.config.get( 'wgFileExtensions' ); -window.licenseSelectorCheck = function() { - var selector = document.getElementById( "wpLicense" ); - var selection = selector.options[selector.selectedIndex].value; - if( selector.selectedIndex > 0 ) { - if( selection == "" ) { +licenseSelectorCheck = window.licenseSelectorCheck = function () { + var selector = document.getElementById( 'wpLicense' ), + selection = selector.options[selector.selectedIndex].value; + if ( selector.selectedIndex > 0 ) { + if ( !selection ) { // Option disabled, but browser is broken and doesn't respect this selector.selectedIndex = 0; } @@ -17,23 +19,29 @@ window.licenseSelectorCheck = function() { function uploadSetup() { // Disable URL box if the URL copy upload source type is not selected - var e = document.getElementById( 'wpSourceTypeurl' ); - if( e ) { - if( !e.checked ) { - var ein = document.getElementById( 'wpUploadFileURL' ); - if(ein) - ein.setAttribute( 'disabled', 'disabled' ); + var ein, + selector, ua, isMacIe, i, + optionsTable, row, td, + wpLicense, wpLicenseRow, wpLicenseTbody, + uploadSourceIds, len, onchange, + e = document.getElementById( 'wpSourceTypeurl' ); + if ( e ) { + if ( !e.checked ) { + ein = document.getElementById( 'wpUploadFileURL' ); + if ( ein ) { + ein.disabled = true; + } } } // For MSIE/Mac: non-breaking spaces cause the